package com.xnyzc.lhy.order.service.impl.order;

import com.xnyzc.lhy.common.entity.Qd;
import com.xnyzc.lhy.common.entity.Qw;
import com.xnyzc.lhy.common.penum.EUserTypeNum;
import com.xnyzc.lhy.order.entity.common.bill.BillRulesCommon;
import com.xnyzc.lhy.order.entity.common.gps.GpsCommon;
import com.xnyzc.lhy.order.entity.common.order.OrderCommon;
import com.xnyzc.lhy.order.entity.order.OaCOrder;
import com.xnyzc.lhy.order.entity.system.OaSysBillRules;
import com.xnyzc.lhy.order.entity.user.OaCUser;
import com.xnyzc.lhy.order.entity.user.OaDUser;
import com.xnyzc.lhy.order.entity.user.OaDUserInfo;
import com.xnyzc.lhy.order.entity.vehicle.OaDDriverVehicle;
import com.xnyzc.lhy.order.mapper.user.OaCUserMapper;
import com.xnyzc.lhy.order.mapper.user.OaDUserInfoMapper;
import com.xnyzc.lhy.order.mapper.user.OaDUserMapper;
import com.xnyzc.lhy.order.mapper.vehicle.OaDDriverVehicleMapper;
import com.xnyzc.lhy.order.service.order.IOaOrderCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

import static com.xnyzc.lhy.common.entity.ParameterEnum.ZERO;

/**
 * @Description netty 服务间调用获取订单相关
 * @Author 刘举
 * @Date 2019/8/16 20:35
 **/
@Service
public class OaOrderCommonServiceImpl implements IOaOrderCommonService {


    @Autowired
    private OrderCommon orderCommon;

    @Autowired
    private BillRulesCommon billRulesCommon;

    @Autowired
    private GpsCommon gpsCommon;

    @Autowired
    private OaCUserMapper userMapper;

    @Autowired
    private OaDUserMapper oaDUserMapper;

    @Autowired
    private OaDUserInfoMapper userInfoMapper;

    @Autowired
    private OaDDriverVehicleMapper dDriverVehicleMapper;

    /**
     * 获取总费用
     *
     * @param totalFee
     * @param baseFee
     * @param userType
     * @param drawRatio
     * @return
     */
    @Override
    public BigDecimal getTotalFee(BigDecimal totalFee, BigDecimal baseFee, Integer userType, BigDecimal drawRatio) {
        BigDecimal startFee = orderCommon.getTotalFee(totalFee, baseFee, EUserTypeNum.c.getValue(), null);
        return startFee;
    }

    /**
     * 获取计费规则费用
     *
     * @param rulesId
     * @param tag
     * @return
     */
    @Override
    public OaSysBillRules getBillRulesStartFee(String rulesId, String tag) {
        OaSysBillRules billRules = billRulesCommon.startFee(rulesId, tag);
        return billRules;
    }

    /**
     * 判断是否评价过
     *
     * @return
     */
    @Override
    public Integer isEvaluation(Long userId, Integer type, String orderNo) {
        Integer isEvaluation = orderCommon.isEvaluation(userId, ZERO.getType(), orderNo);
        return isEvaluation;
    }

    /**
     * 获取历史轨迹
     *
     * @param orderNo
     * @return
     */
    @Override
    public List<Qd> getHistroyGpsList(String orderNo) {
        List<Qd> gpsList = gpsCommon.getHistroyGpsList(orderNo);
        return gpsList;
    }

    /**
     * 获取订单信息
     *
     * @param orderNo
     * @return
     */
    @Override
    public OaCOrder getOrderInfo(String orderNo) {
        OaCOrder order = orderCommon.selectOn(orderNo);
        return order;
    }

    /**
     * 获取用户信息
     *
     * @param userId
     * @return
     */
    @Override
    public OaCUser getUserInfo(Long userId) {
        OaCUser oaCUser = userMapper.selectById(userId);
        return oaCUser;
    }
    /**
     * 获取司机用户信息
     *
     * @param driverId
     * @return
     */
    @Override
    public OaDUser getOaDUser(Long driverId) {
        OaDUser oaDUser = oaDUserMapper.selectById(driverId);
        return oaDUser;
    }

    /**
     * 获取司机用户信息详情
     *
     * @param driverId
     * @return
     */
    @Override
    public OaDUserInfo getOaDUserInfo(Long driverId) {
        OaDUserInfo userInfo = userInfoMapper.selectOne(Qw.create().eq(OaDUserInfo.DRIVER_ID, driverId));
        return userInfo;
    }

    /**
     * 获取司机车辆信息
     *
     * @param driverId
     * @param isUse
     * @return
     */
    @Override
    public OaDDriverVehicle getOaDDriverVehicleInfo(Long driverId, Integer isUse) {
        OaDDriverVehicle oaDDriverVehicle = dDriverVehicleMapper.selectOne(Qw.create().eq(OaDDriverVehicle.DRIVER_ID, driverId).eq(OaDDriverVehicle.IS_USE, isUse));
        return oaDDriverVehicle;
    }


}
